"""MxShop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.views.static import serve
from django.conf.urls import url
from django.conf import settings
from django.views.generic import TemplateView
from rest_framework.documentation import include_docs_urls
from rest_framework.routers import DefaultRouter
from rest_framework.authtoken import views
import social_django.urls
from rest_framework_jwt.views import obtain_jwt_token

import xadmin

from goods.views import GoodsListViewSet, GoodsCategoryViewSet, BannerViewSet, IndexCategoryViewSet
from trade.views import ShoppingCartViewset, OrderViewset, AlipayView
from users.views import SmsCodeViewSet, UserViewset
from user_operation.views import UserFavViewSet, LeavingMessageViewset,\
    AddressViewset


goods_list = GoodsListViewSet.as_view({ 
    'get': 'list',
})
router = DefaultRouter()
# 配置goods的url
router.register(r'goods', GoodsListViewSet, basename='goods')
# 配置category的url
router.register(r'category', GoodsCategoryViewSet, basename='category')
# 生成短信验证码
router.register(r'codes', SmsCodeViewSet, basename='codes')
# 用户操作
router.register(r'users', UserViewset, basename='users')
# 用户收藏
router.register(r'userfavs', UserFavViewSet, basename='userfavs')
# 用户留言
router.register(r'messages', LeavingMessageViewset, basename='messages')
# 用户地址
router.register(r'address', AddressViewset, basename='address')
# 购物车
router.register(r'shopcarts', ShoppingCartViewset, basename='shopcarts')
# 订单
router.register(r'orders', OrderViewset, basename='orders')
# 轮播图
router.register(r'banners', BannerViewSet, basename='banners')
# 首页商品系列数据
router.register(r'index_goods', IndexCategoryViewSet, basename='index_goods')


urlpatterns = [
    path('admin/', admin.site.urls),
    path('xadmin/', xadmin.site.urls),
    # 配置上传文件访问的url
    url(r'^media/(?P<path>.*$)', serve, {"document_root": settings.MEDIA_ROOT}),
    # 不使用Router配置商品列表页
    # url(r'goods/$', goods_list, name="goods-list"),
    # 使用Router配置url
    url(r'^', include(router.urls)),
    # 引入drf文档
    path('docs/', include_docs_urls(title='慕学生鲜')),
    # 引入drf登录
    path('api-auth/', include('rest_framework.urls')),
    # 引入drf自带的的token认证模式
    # url(r'api-token-auth/', views.obtain_auth_token),
    # jwt的认证接口，用户登录
    url(r'^login/&', obtain_jwt_token),
    # 支付宝支付接口
    url(r'^alipay/return/', AlipayView.as_view(), name="alipay"),
    url(r'^index/', TemplateView.as_view(template_name="index.html"), name="index"),
    # 第三方登录
    url('', include('social_django.urls', namespace='social'))
]
